package dailyAccessCount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.util.GenericOptionsParser;

public class MyDriver {
//    public static void main(String[] args) throws Exception{
//        Configuration conf = new Configuration();
//        Job job = Job.getInstance(conf,"Daily Access Count");
//        job.setJarByClass(MyDriver.class);
//        job.setMapperClass(MyMapper.class);
//        job.setReducerClass(MyReducer.class);
//        job.setMapOutputKeyClass(Text.class);
//        job.setMapOutputValueClass(IntWritable.class);
//
//        job.setOutputKeyClass(Text.class);
//        job.setOutputValueClass(IntWritable.class);
//
//        FileInputFormat.setInputPaths(job, new Path("D:/other/data/user_login.txt"));
//        FileOutputFormat.setOutputPath(job,new Path("D:/other/data/out"));
//        System.exit(job.waitForCompletion(true) ? 0:1);
//    }
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
        if (otherArgs.length < 2) {
            System.err.println("Usage: wordcount <in> [<in>···] <out>");
            System.exit(2);
        }
        Job job = Job.getInstance(conf, "Daily Access Count");
        job.setJarByClass(MyDriver.class);
        job.setMapperClass(MyMapper.class);;
        job.setReducerClass(MyReducer.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job. setOutputValueClass(IntWritable. class);


        FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
        FileOutputFormat.setOutputPath( job, new Path(otherArgs [1]));
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}